/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.qdu.servlet;

import com.qdu.entity.Movie;
import com.qdu.service.MovieService;
import com.qdu.service.impl.MovieServiceImpl;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Lenovo
 */
@WebServlet("/ams")
public class AddMovieServlet extends HttpServlet {
       MovieService movieService=new MovieServiceImpl();
        @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1. 获取请求参数
        //获取新注册的电影的信息，封装成一个电影对象
        req.setCharacterEncoding("utf-8");
        String movieId = req.getParameter("movieId");
        String mchineseName = req.getParameter("mchineseName");
        String moriginalName = req.getParameter("moriginalName");
        String mtype = req.getParameter("mtype");
        
        String mreleaseDate = req.getParameter("mreleaseDate");
        String mlanguage = req.getParameter("mlanguage");
        String mcountry = req.getParameter("mcountry");
        int mlength = Integer.parseInt("mlength");
        String mdigest = req.getParameter("mdigest");
        String mcover = req.getParameter("mcover");
        String mdirector = req.getParameter("mdirector");
       float  mrating = Float.parseFloat("mrating");
        

        
        Movie newMovie = new Movie(movieId, mchineseName, moriginalName, mtype,mreleaseDate, mlanguage,mcountry,mlength,mdigest,mcover,mdirector,mrating);

        //2. 调用业务类方法执行业务逻辑，完成请求处理
        int rows = movieService.registerNewMovie(newMovie);

        //3. 生成响应内容，这里直接返回了受影响的行数，用于判断是否插入成功
        resp.getWriter().println(rows);
    }
}
